﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【磁头】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto检测报告
    /// </summary>
    public abstract class AutoMHCheckMapping : BaseMapping<MHCheck, MHCheckModel, MHCheckFilterModel>
    {
        public AutoMHCheckMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override MHCheckModel Entity2Model(MHCheck entity)
        {
            MHCheckModel model = new MHCheckModel();

            model.MHCheckID = entity.MHCheckID;
            model.MHID = entity.MHID;
            model.GroupInfoID = entity.GroupInfoID;
            model.DeviceID = entity.DeviceID;

            model.WireropeType = entity.WireropeType;
            model.WireropeSN = entity.WireropeSN;
            model.Diameter = entity.Diameter;
            model.Company = entity.Company;
            model.ResponsiblePerson = entity.ResponsiblePerson;

            model.ReportName = entity.ReportName;
            model.CheckTime = entity.CheckTime;
            model.State = entity.State;
            model.Content = entity.Content;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override MHCheck Model2Entity(MHCheckModel model)
        {
            MHCheck entity = new MHCheck();

            entity.MHCheckID = model.MHCheckID;
            entity.MHID = model.MHID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.DeviceID = model.DeviceID;

            entity.WireropeType = model.WireropeType;
            entity.WireropeSN = model.WireropeSN;
            entity.Diameter = model.Diameter;
            entity.Company = model.Company;
            entity.ResponsiblePerson = model.ResponsiblePerson;
            
            entity.ReportName = model.ReportName;
            entity.CheckTime = model.CheckTime;
            entity.State = model.State;
            entity.Content = model.Content;
            
            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<MHCheck> FilterModel2Where(MHCheckFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._MHCheckID.HasValue)
            {
                where = where.And(x => x.MHID == filterModel._MHCheckID.Value);
            }
            if (filterModel._MHCheckIDs.IsNotEmpty() && filterModel._MHCheckIDs.Count > 0)
            {
                where = where.And(x => filterModel._MHCheckIDs.Contains(x.MHCheckID));
            }
            if (filterModel._NotMHCheckIDs.IsNotEmpty() && filterModel._NotMHCheckIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotMHCheckIDs.Contains(x.MHCheckID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //设备
            //if (filterModel._DeviceID.HasValue)
            //{
            //    where = where.And(x => x.DeviceID == filterModel._DeviceID);
            //}
            //if (filterModel._DeviceIDs.IsNotEmpty() && filterModel._DeviceIDs.Count > 0)
            //{
            //    where = where.And(x => filterModel._DeviceIDs.Contains(x.DeviceID));
            //}
            //if (filterModel._NotDeviceIDs.IsNotEmpty() && filterModel._NotDeviceIDs.Count > 0)
            //{
            //    where = where.And(x => !filterModel._NotDeviceIDs.Contains(x.DeviceID));
            //}

            //钢丝绳类型
            if (!string.IsNullOrEmpty(filterModel._WireropeType))
            {
                where = where.And(x => x.WireropeType == filterModel._WireropeType);
            }
            if (!string.IsNullOrEmpty(filterModel._WireropeTypeEqual))
            {
                where = where.And(x => x.WireropeType == filterModel._WireropeTypeEqual);
            }

            //钢丝绳编号
            if (!string.IsNullOrEmpty(filterModel._WireropeSN))
            {
                where = where.And(x => x.WireropeSN == filterModel._WireropeSN);
            }
            if (!string.IsNullOrEmpty(filterModel._WireropeSNEqual))
            {
                where = where.And(x => x.WireropeSN == filterModel._WireropeSNEqual);
            }

            //钢丝绳直径
            if (filterModel._Diameter.HasValue)
            {
                where = where.And(x => x.Diameter == filterModel._Diameter.Value);
            }
            if (filterModel._Diameters.IsNotEmpty() && filterModel._Diameters.Count > 0)
            {
                where = where.And(x => filterModel._Diameters.Contains(x.Diameter));
            }
            if (filterModel._NotDiameters.IsNotEmpty() && filterModel._NotDiameters.Count > 0)
            {
                where = where.And(x => !filterModel._NotDiameters.Contains(x.Diameter));
            }

            //公司
            if (!string.IsNullOrEmpty(filterModel._Company))
            {
                where = where.And(x => x.Company == filterModel._Company);
            }
            if (!string.IsNullOrEmpty(filterModel._CompanyEqual))
            {
                where = where.And(x => x.Company == filterModel._CompanyEqual);
            }

            //负责人
            if (!string.IsNullOrEmpty(filterModel._ResponsiblePerson))
            {
                where = where.And(x => x.ResponsiblePerson == filterModel._ResponsiblePerson);
            }
            if (!string.IsNullOrEmpty(filterModel._ResponsiblePersonEqual))
            {
                where = where.And(x => x.ResponsiblePerson == filterModel._ResponsiblePersonEqual);
            }            

            //报告名称
            if (!string.IsNullOrEmpty(filterModel._ReportName))
            {
                where = where.And(x => x.ReportName == filterModel._ReportName);
            }
            if (!string.IsNullOrEmpty(filterModel._ReportNameEqual))
            {
                where = where.And(x => x.ReportName == filterModel._ReportNameEqual);
            }

             //报告生成时间
            if (filterModel._CheckTime.HasValue)
            {
                where = where.And(x => x.CheckTime == filterModel._CheckTime);
            }
            if (filterModel._CheckTime_Begin.HasValue)
            {
                where = where.And(x => x.CheckTime >= filterModel._CheckTime_Begin.Value);
            }
            if (filterModel._CheckTime_End.HasValue)
            {
                where = where.And(x => x.CheckTime <= filterModel._CheckTime_End.Value);
            }

            //状态
            if (!string.IsNullOrEmpty(filterModel._State))
            {
                where = where.And(x => x.State == filterModel._State);
            }
            if (!string.IsNullOrEmpty(filterModel._StateEqual))
            {
                where = where.And(x => x.State == filterModel._StateEqual);
            }

            //内容
            if (!string.IsNullOrEmpty(filterModel._Content))
            {
                where = where.And(x => x.Content == filterModel._Content);
            }
            if (!string.IsNullOrEmpty(filterModel._ContentEqual))
            {
                where = where.And(x => x.Content == filterModel._ContentEqual);
            }
            return where;
        }
        #endregion
    }
}

